Array.prototype.my_reduce = function (callback, initialValue) {
    if(!Array.isArray(this)||typeof callback !== 'function'||this.length === 0) {
        return []
    }else{
        let value = initialValue !== 'undefined'? initialValue : this[0]
        for(let index = initialValue?0:1; index < this.length; index++) {
            value = callback(value,this[index],index,this)
        }
        return value
    }
}

let arr = [1,2,3,4]
console.log(arr.my_reduce((sum,next,index) => {
    return sum + next
},-10))